<?php
/*
 * Created on Apr 2, 2006
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */

require_once('sql_connection.php');
require_once('functions/sql.php');

class Sql_search extends Sql_connection {
	function __construct() {
		parent :: __construct();
	}
	
	/**
	 * Full text-search on incident. Searches through user, area,
	 * offense, offender and comment.
	 */
	function search_incident($terms) {
		$terms = mysql_input($terms);

		//SQL is the COBOL of the 21st century.
		//This finds matches and orders results by score.
		$query = "SELECT *, MATCH (user, area, offense, offender, comment) AGAINST
					('$terms') AS score FROM Incident
					WHERE MATCH(user, area, offense, offender, comment) AGAINST ('$terms')";
		
		$result = mysql_query($query);
		
		if (!$result)
			die ("Could not run query, error from DB:" . mysql_error());
		
		if (mysql_num_rows($result) == 0)
			return null; //no results.
		
		$data = Array();
		while($row = mysql_fetch_assoc($result))
			$data[] = $row;
			
		return $data;
	}
	
	function search_incident_advanced($_POST) {
		
		 //TODO: Figure this one out.
		
		if ($_POST[terms])
			return search_incident($_POST[terms]);
			
		return false;
		
	}
	
	function parse_bookmark($bookmark) {
		//TODO:
	}
}

?>